<?php
echo "abc";
require_once "ByteBuffer.php";
require_once "DataUtil.php";
require_once "FunctionData.php";
require_once "DataUserRegister.php";
$memcache = new Memcache;
$memcache->addServer("192.168.1.3", 11212);
$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";
echo "Test r/w int 8 <br/>\n";
$i8 = 8;
$d8 = ByteBuffer::allocate(1);
DataUtil::writeInt8($d8,$i8);
$memcache->set('int8',$d8->_array());
$rs8 = $memcache->get('int8');
$d8 = new ByteBuffer($rs8);
$i8 = DataUtil::readInt8( $d8 ) ;
echo "Value:". $i8. "<br/>\n";
echo "Test r/w int 16 <br/>\n";
$i16 = 16;
$d16 = ByteBuffer::allocate(2);
DataUtil::writeInt16($d16,$i16);
$memcache->set('int16',$d16->_array());
$rs16 = $memcache->get('int16');
$d16 = new ByteBuffer($rs16);
$i16 = DataUtil::readInt16($d16);
echo "Value:". $i16. "<br/>\n";
echo "Test r/w int 32 <br/>\n";
$i32 = 32;
$d32 = ByteBuffer::allocate(4);
DataUtil::writeInt32($d32,$i32);
$memcache->set('int32',$d32->_array());
$rs32 = $memcache->get('int32');
$d32 = new ByteBuffer($rs32);
$i32 = DataUtil::readInt32($d32);
echo "Value:". $i32. "<br/>\n";
$bin = Array();
for($i = 0; $i< 15; $i++){
	$bin[] = $i;
}
$dbin = ByteBuffer::allocate(15);
DataUtil::writeBytes($dbin,$bin);
$memcache->set("bins",$dbin->_array());
$rsbin = $memcache->get("bins");
$dbin = new ByteBuffer($rsbin);
$bin = DataUtil::readBytes($dbin,15);
echo "bytes value:";
for($i = 0; $i< 15; $i++){
	echo ".".$bin[$i];
}
echo "<br/>";
echo "Test r/w BBin <br/>\n";
$blen = 50;
$bin = Array();
for($i = 0; $i< $blen; $i++){
	$bin[] = $i; 
}
$dbin = ByteBuffer::allocate(1 + $blen);
DataUtil::writeBBin($dbin,$bin);
$rsbin = $dbin->_array();
$memcache->set('bbin',$dbin->_array());
$rsbin = $memcache->get('bbin');
$dbin = new ByteBuffer($rsbin);
$bin = DataUtil::readBBin($dbin);
echo "read value <br/>\n";
for($i = 0; $i< count($bin); $i++){
	echo ".".$bin[$i];
}
echo "<br/>\n";
$user = new DataUserRegister();
$user->MailAddressBytes = unpack('C*', "duy.nguyen@colorbox.com.vn" ) ;
$buf = $user->getBinary();
$memcache->set("testuser",$buf->_array());
$duser = $memcache->get("testuser");
$buf = new ByteBuffer($duser);
$user = DataUserRegister::swap($buf);
echo implode(array_map("chr",  $user->MailAddressBytes )) ."<br/>\n";
?>